home *** CD-ROM | disk | FTP | other *** search
- {---------------------------------------------------------------------
- EVALUATOR UNIT TEST PROGRAM
- Arthur Zatarain, P.E. C'Serve 3417-525 Bixen=ARTZAT
- Total Engineering Services Team, Inc. (TEST Inc).
- New Orleans, La. (504) 368-6792 Days
- 837-3699 Nites
-
- This program demonstrates the use of the evaluator unit and the
- notions of variable list objects. This acts as a shell into the
- evaluator by allocating and deallocation variable, and providing
- a few demonstration functions.
-
- The functions that can be added into the evaluator via the virtual
- method can only take single real value and return a single real.
-
- -----------------------------------------------------------------------}
- program evaltest;
-
- uses tpcrt, evaluate, testlib, printf, tpstring;
- const
- version = 'July 13, 1989 AMZ';
- max_vars = 32; { 32 variables allowed in this test}
- type
-
- our_eval = object(eval_type) { hook into the evaluator }
- constructor init;
- function ext_fun_search(s : small_string) : integer; virtual;
- function ext_fun_execute(i : integer; v1 : real) : real; virtual;
- procedure ext_error(s :string); virtual;
- end;
-
-
- var
- aline : string;
- ablock : our_eval;
- a_list : a_var_list; { object that holds variable control block for our test }
- ready : boolean;
-
-
- i : integer;
- processed : boolean;
- tempstr : string[40];
- constructor our_eval.init;
- begin
- eval_type.init; { init the main evaluator}
- end;
-
- function our_eval.ext_fun_search(s : small_string) : integer;
- var
- j : integer;
- begin
- j := 0; { asssume no external function matches }
- if s = 'ONE' then j := 1;
- if s = 'TWO' then j := 2;
- if s = 'TRREE' then j := 3;
- ext_fun_search := j;
- end;
-
-
- { these are dummy functions do demonstrate the capabilities }
-
- function our_eval.ext_fun_execute(i : integer; v1 : real) : real;
- begin
- case i of
- 3 : ext_fun_execute := v1;
- 2 : ext_fun_execute := v1 * 2;
- 3 : ext_fun_execute := v1 * 3;
- end;
- end;
-
-
- procedure our_eval.ext_error(s :string);
- begin
- writeln; blip;
- writeln('EVAL ERROR: ', s);
- end;
-
-
- BEGIN { main program start }
- writeln;
- writeln('Expression Evalulator Test');
- writeln('Arthur Zatarain, P.E.');
- writeln('Total Engineering Services Team, Inc. (TEST, Inc.');
- writeln('Version ',version);
- writeln;
-
- ablock.init; { set up the evaluator }
- a_list.init(max_vars); { set up the variable table as empty }
- ablock.set_var_list(@a_list);
-
- with ablock, a_list do begin
- ready := false;
- repeat
- processed := false;
- Write('Enter Expression (or ?) : '); ReadLn(aline);
-
- if aline[1] = '$' then begin { create a new variable }
- processed := true;
- ready := true;
- end; { if terminating}
-
- if aline[1] = '@' then begin { create a new variable }
- processed := true;
- tempstr := copy(aline,2,12);
- tempstr := stupcase(tempstr);
- tempstr := trim(tempstr); { clean string}
- if add_name(tempstr,i) then
- writeln('New Variable ',tempstr, ' at index ',i)
- else
- writeln('Variable creation error!');
- end; { if starting a new variable }
-
- if aline[1] = '#' then begin { delete a variable }
- processed := true;
- tempstr := copy(aline,2,12);
- tempstr := stupcase(tempstr);
- tempstr := trim(tempstr); { clean string}
- delete_name(tempstr);
- end; { if deleteing variable }
-
- if aline[1] = '?' then begin
-
- processed := true;
- for i := 1 to max_vars do with var_list^[i] do begin
- if var_name <> '' then writeln(i, ' ',var_name,' ',var_value:1:2);
- end;
- writeln('@ = New Var # = Delete Var ? = Var listing $ = Exit');
- end;
-
- if not processed then begin
- aline := stupcase(aline); { ALWAYS SEND IN UPPER CASE AT THIS POINT}
- if do_evaluate(aline) then begin
- writeln;
- writeln('Result= ', eval_result:1:4)
- end
- else writeln('Error');
- end;
- until ready;
- clrscr; gotoxy(1,20);
- writeln('Evaluator Test Program Normal Termination');
- writeln('Y''all come back nah, y''a hear!');
- end;
- end.
-
-